package org.javaboy.swagger2.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableWebMvc
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig {

    public ApiInfo apiInfo() {
        return  new ApiInfoBuilder()
                .title("模具排程相关 API")
                .description("部分数据来源：模德宝、快表数据")
                .termsOfServiceUrl("")//这里可以是项目地址
                .version("2.0.1")
                .build();
    }

    public ApiInfo apiInfoprdt() {
        return  new ApiInfoBuilder()
                .title("模具与产品 API")
                .description("基础数据配置")
                .termsOfServiceUrl("")//这里可以是项目地址
                .version("2.0.1")
                .build();
    }

    @Bean
    public Docket userApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfoprdt())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/user/**"))
                .build()
                .groupName("用户管理")
                .pathMapping("/");
    }

    @Bean
    public Docket testApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/test/**"))
                .build()
                .groupName("多级目录测试")
                .pathMapping("/");
    }

}